<?php
	/**
	* Products Module Datatype
	* @author trungdt
	* @since Sep 27, 2011
	* 
	*/
	class file_manager{
		function product_form($object, $config) {
			global $user;

			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			exponent_forms_initialize();
			
			// check permission, for some fields for the admin
			$loc=unserialize($config->location_data);
			// permission checking
			$have_permission=false;
			if (exponent_users_isAdmin() || exponent_permissions_check('administrate',$loc) || exponent_permissions_check('create',$loc) || exponent_permissions_check('edit',$loc))
			{
				$have_permission=true;
			}
			
			$lang=exponent_lang_loadFile("modules/surveymodule/common.php");


			$form = new form();
			if (!isset($object->id)) {
				$object->title = '';
				$object->seo_name='';
				$object->search_des = '';
				$object->cat_id = productsmodule::GetFirstCategoryId();
				$object->post_date=time();                                           $object->og_thumbnail=0; // og thumbnail image file path
				$object->best_seller=0;
				$object->images="";
				$object->description="";
				$object->spec="";
				$object->brand_id=0;
				$object->sku='';
				$object->price=0;
				$object->price_orginal=0;
				$object->product_state=0;
				$object->user_id=$user->id;
				$object->videos="";
				$object->stars=1;
				$object->product_state2=0;
				$object->on_sale=0;
				$object->hot_product=0;
				$object->stock_remain=0;
			} else {
				$form->meta('id',$object->id);
			}

			$form->register('title','Product Name',new textcontrol($object->title));
			$form->register('seo_name','Seo Name',new textcontrol($object->seo_name));
			$form->register("",null,new htmlcontrol("<p>Leave SEO field blank for automatic generate SEO name</p>"));
			$form->register('search_des','Search Description',new texteditorcontrol($object->search_des,3,90));

			$form->register('og_thumbnail','Thumbnail', new ajax_select_file('og_thumbnail',0,$object->og_thumbnail,true));
			
			// price
			$form->register("price", $lang['product_price'], new textcontrol($object->price, 60, false, 20, "","number"));
			
			//$object->cat_id = productsmodule::GetFirstCategoryId();
			$form->register("description", "Product Description", new htmleditorcontrol($object->description));
			$form->register("spec", "Product Specification", new htmleditorcontrol($object->spec));
			
			$form->register("best_seller", "Best Selling", new checkboxcontrol($object->best_seller,true));
			$form->register("on_sale", "On Sale", new checkboxcontrol($object->on_sale,true));
			$form->register("hot_product", "This is a hot product (show hot product icon)?", new checkboxcontrol($object->hot_product,true));
			$form->register("stock_remain", "How many items remain in your stock?", new textcontrol($object->stock_remain, 50, false, 10, "","digits"));
			
			// rating stars
			$stars=array();
			for ($i=0;$i<=5;$i++)
				$stars[$i]=str_repeat("*",$i+1);
			$form->register('stars',$lang['product_stars'],new dropdowncontrol($object->stars,$stars));
			
			// product state
			$product_state=array();
			for ($i=0;$i<$lang['product_state_count'];$i++)
			{
				$product_state[$i]=$lang["product_state{$i}"];
			}

			$form->register('product_state',$lang['product_state'],new dropdowncontrol($object->product_state,$product_state));
			
			// product state2
			$product_state2=array();
			for ($i=0;$i<$lang['product_state_2_count'];$i++)
			{
				$product_state2[$i]=$lang["product_state_2_{$i}"];
			}

			$form->register('product_state2',$lang['product_state_2'],new dropdowncontrol($object->product_state2,$product_state2));
			
			//$object->images="";
			
			//$object->brand_id=0;
			//$object->sku='';
			/*$object->price=0;
			$object->=0;
			$object->user_id=$user->id;
			$object->videos="";

*/
			
			if ($have_permission)
			{
				$form->register("",null, new htmlcontrol("<h1>{$lang['data_modeler_forAdminOnly']}</h1>"));
				// price buy
				$form->register("price_orginal", $lang['product_price_orginal'], new textcontrol($object->price_orginal, 60, false, 20, "","number"));
				
				 
			}
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}
		
		/**
		* Product Update to Modeler data
		* 
		* @author trungdt
		* @since Oct 3, 2011
		* @param mixed $values
		* @param mixed $object
		*/

       
        function file_update($values,$object) {
            $user_id = $values['user_id'];
            $homedir = $values['homedir'];
            $show_hidden = $values['show_hidden'];
            $pattern_hidden = $values['pattern_hidden'];
            $per = $values['per'];
            
            $object->active = 0;
            $object->user_id = $user_id;
            $object->homedir = $homedir;
            $object->show_hidden = $show_hidden;
            $object->pattern_hidden = $pattern_hidden;
            $object->permissions = $per;
            
            return $object;
        }
	}
?>
